package com.forum.controller.handler;

import com.common.entity.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpRequest;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.sql.SQLException;

/**
 * @author Tsing
 * 全局异常捕捉类
 */
@ControllerAdvice
@Slf4j
public class ForumGlobalExceptionHandler {


    /**
     * 异常捕捉
     * **/
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ApiResult<String> exceptionHandler(HttpServletRequest request,Exception e){
        log.error("请求路径为："+request.getRequestURI()+"\t"+"异常类型为："+e);
        return ApiResult.fail(HttpStatus.INTERNAL_SERVER_ERROR.value(),e.toString());
    }

}
